    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>oninput</title>
    </head>
    <body>
    <form action="">
        <fieldset>
            <label for="">
                <input type="email" name="email" id="txt1">
            </label><br>
            <label for="">
                <input type="text" name="text" id="txt2">
            </label>
            <input type="submit" value="提交">
        </fieldset>
    </form>
    <script>
        var txt1=document.getElementById('txt1');
        var txt2=document.getElementById('txt2');
        var num=0;
        txt1.oninput=function () {
                num++;
                txt2.value=num;
        }
        txt1.oninvalid=function () {
            this.setCustomValidity('你是不是傻？')
        }
    </script>
    </body>
    </html>